package 数组;

import java.util.ArrayList;
import java.util.List;

class Solution{
    public static List<List<Integer>> subsets(int[] nums) {
        int n=nums.length;
        List<List<Integer>> ans=new ArrayList<>();
        List<Integer> path=new ArrayList<>();
        ans.add(new ArrayList<>());
        dfs(ans,nums,0,path);
        return ans;
    }
    public static void dfs(List<List<Integer>> ans,int[] nums,int start,List<Integer> path){
        if(path.size()<=nums.length){
            ans.add(new ArrayList<>(path));
        }
        if(start==nums.length) return;

        for(int i=start;i<nums.length;++i){
            path.add(nums[i]);
            dfs(ans,nums,i+1,path);
            path.remove(path.size()-1);
        }
    }

    public static void main(String[] args) {
        System.out.println(subsets(new int[]{1,2,3,4}));
    }
}

